<!--
    已激活案件列表 弹窗 公共插件

    参数：
    modal       弹窗开关
    modalTitle  弹窗title

    dataDict    数据字典

    方法:

    closeModal          关闭弹窗
 -->
<template>
    <Modal
        :title="modalTitle"
        v-model="isModalOpen"

        :width="950"
        @on-cancel="cancel"
    >
        <div class="addContract">
            <!-- 全部模糊查询 -->
            <Form ref="formValidate" :model="formValidate" :label-width="100" >
                <Row>
                    <Col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" :xxl="12">
                        <FormItem label="合同名称" prop="printFormName">
                            <Select v-model="printFormName" placeholder="请选择" clearable @on-change="iWantOneVersionId()">
                                <Option v-for="(item) in  this.ContractReissurVo2"  :value="item.printFormName"  >
                                    {{item.printFormName}}
                                </Option>
                            </Select>
                        </FormItem>
                    </Col>

                    <Col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" :xxl="12">
                        <FormItem label="合同版本号" prop="versionId">
                            <Select v-model="versionId" placeholder="请选择"  clearable >
                                <Option v-for="(item) in  this.ContractReissurVo3"  :value="item.versionId"  >
                                    {{item.versionId}}
                                </Option>
                            </Select>
                        </FormItem>

                    </Col>
                    <Col span="24">
                        <div class="text-center contract-close-btns">
                            <Button type="primary" @click="handleSubmit('formValidate')" style="margin-right:16px">添加</Button>
                        </div>
                    </Col>
                </Row>
            </Form>
        </div>
        <div slot="footer"></div>
    </Modal>
</template>

<script>

    import {queryContractByName,addContractFile} from "_p/basic/api/contract/contract-reissue/index";
    export default {
        // 已激活案件列表 弹窗
        name: "addContract",
        components: {},
        props: {
            isModalOpen: {
                type: Boolean,
                required: true
            },
            closeModal:{

            },
            ContractReissurVo2: {
                type: Array,
                required: true
            },
            contractNo: {
                type: String,
                required: true
            },
            modalTitle: {
                type: String,
                default: "已激活案件列表"
            },

        },
        data() {
            return {
                loading: false,
                formValidate: {
                    printFormName: "", // 合同名称
                    versionId: "", // 合同版本号
                    printNode:"",
                    belongNo:"",
                    busiNo:'',
                },
                ContractReissurVo3:[],
                versionList:"",
                versionId:"",
                printFormName:"",
                ruleInline: {

                },

            };
        },
        watch: {
            isModalOpen: function (newVal) {
                if (newVal) {
                    this.isModalOpen = newVal;
                    this.loading = true;
                }
            }
        },
        created() {

        },
        mounted() {
            this.init();

        },
        methods: {
            init() {
            },
            handleSubmit(date) {
                this.$refs[date].validate((valid) => {
                    if (valid) {
                        this.formValidate.printFormName=this.printFormName
                        this.formValidate.versionId=this.versionId
                        this.formValidate.belongNo=this.contractNo
                        addContractFile(this.formValidate).then( res=>{
                                if (res.code === "0000") {
                                    this.$emit("addContract",this.formValidate)
                                }
                            }
                        )
                        this.$emit("closeModal")
                    } else {
                        this.$Message.error('Fail!');
                    }
                })
            },
            cancel(){
                this.$emit("closeModal")
            },
            iWantOneVersionId() {
                this.formValidate.printNode = 'printLoanApply'
                this.formValidate.printFormName = this.printFormName
                queryContractByName(this.formValidate).then(
                    res => {
                        if (res.code === "0000") {
                            console.log("res.data", res.data)
                            this.ContractReissurVo3 = res.data
                            this.ContractReissurVo3.forEach(ContractRList=>{
                                this.printFormName = ContractRList.printFormName
                                this.formValidate.busiNo=ContractRList.id
                                this.versionId = ContractRList.versionId
                            })
                        }
                    }
                )
            },
        }
    };
</script>
<style scoped lang="less">
    .vertical-center-modal {
        display: flex;
        align-items: center;
        justify-content: center;

        .ivu-modal {
            top: 0;
        }
    }

    .ActivatedCase {
        .new-apply-table {
            padding-top: 18px;
        }

        .table-page {
            padding-top: 16px;
        }
    }

    .text-center {
        text-align: center;
    }
</style>
